package com.pengheng.transformation.base;

import com.pengheng.bean.WaterSensor;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 过滤 基本转换算子
 */
public class TransFilter {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> streamSource = env.fromElements(
                new WaterSensor("sensor1", 1L, 1),
                new WaterSensor("sensor1", 2L, 2),
                new WaterSensor("sensor2", 2L, 2),
                new WaterSensor("sensor3", 3L, 3)
        );

        streamSource.filter(new UserFilter()).print();

        env.execute();


    }

    private static class UserFilter implements FilterFunction<WaterSensor> {
        @Override
        public boolean filter(WaterSensor waterSensor) throws Exception {
            return waterSensor.ts == 1L || waterSensor.vc == 2;
        }
    }
}
